<?php
/**
 * Created by PhpStorm.
 * User: yuchen
 * Date: 16/5/13
 * Time: 下午4:27
 */

namespace App\Http\Controllers;

/**
 * File: ExamController.php
 * User: lyc
 * Date: 16/3/28
 * Time: 下午12:11
 */

namespace App\Http\Controllers;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Auth;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Input;
use PHPExcel;
use PHPExcel_IOFactory;
use DB;
use Hash;
use Illuminate\Support\Str;
use Cache;
use Illuminate\Support\Facades\File;

class PiController extends Controller
{
    public function getData(Request $request)
    {
        $temperature = $request->input("temperature");
        $humidity = $request->input("humidity");
        $yudi = $request->input("value");
        $pressure = $request->input("pressure");
        if($temperature > 0)
        {
            Cache::put("Pi_temperature",$temperature,600);

        }
        if($humidity > 0){
            Cache::put("Pi_humidity",$humidity,600);
        }
        if($yudi > 0){
            Cache::put("Pi_yudi",$yudi,600);
        }
        if($pressure > 0)
        {
            Cache::put("Pi_pressure",$pressure,600);
        }
        echo "temp: ";
        echo $temperature;
        echo " h: ";
        echo $humidity;
        echo " yudi:";
        echo Cache::get("Pi_yudi");
        echo "  ";
        echo " pressure: ";
        echo  $pressure;
        echo "  ";

    }

    public function showData(Request $request)
    {
        $temperature_type = $request->input("temperature");
        $humidity_type = $request->input("humidity");
        $yudi_type = $request->input("yudi");
        $pressure_type = $request->input("pressure");
        $temperature = Cache::get($temperature_type);
        $humidity = Cache::get($humidity_type);
        $yudi = Cache::get($yudi_type) - 1;
        $pressure = Cache::get($pressure_type);
        return response()->json([$temperature_type => $temperature,$humidity_type => $humidity,$yudi_type=>$yudi,$pressure_type=>$pressure]);
    }
}